package cn.swing.his.finance.webapi.service.impl;

import cn.swing.his.finance.service.IPrescriptionService;
import cn.swing.his.finance.webapi.mapper.PrescriptionMapper;
import cn.swing.his.pojo.finance.vo.PrescriptionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

@Service
@Slf4j
public class PrescriptionServiceImpl implements IPrescriptionService {
    @Autowired
    private PrescriptionMapper prescriptionMapper;


    @Override
    public void updateMedicineById(Integer patientId) {
//        修改状态
        prescriptionMapper.updateMedicineById(1,patientId);
    }

    @Override
    public List<PrescriptionVO> selectPrescriptionByPatientId(Integer patientId) {
        List<PrescriptionVO> list=prescriptionMapper.selectPrescriptionByPatientId(patientId);
        DecimalFormat df = new DecimalFormat("#.00");
        for (PrescriptionVO prescriptionVO:list) {
            prescriptionVO.setTotalPrice(Double.valueOf(df.format(prescriptionVO.getPurchasedNumber()*prescriptionVO.getSalePrice())));
        }
        return list;
    }
}
